<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
<style type="text/css">
.ftitle{
    font-size:14px;
    font-weight:bold;
    padding:5px 0;
    margin-bottom:10px;
    border-bottom:1px solid #ccc;
}
.fitem{
    margin-bottom:10px;
}
.fitem label{
    display:inline-block;
    text-align:right;
    width: 25%;
}
</style>
</head>
<body style="padding: 15px">
<form id="form1" method="post">
	<input name="id"  class="mini-hidden"/>
	<div class="fitem">
	    <label>字典表键：</label>
		<input name="keyName" onblur="judgekeyName();" class="mini-textbox" required="true" style="width: 170px"/>
		<input name="keyNameHidden" class="mini-hidden" />
	</div>
	<div class="fitem">
		<label>字典表值：</label>
		<input name="keyValue" class="mini-textbox" required="true" style="width: 170px"/>
	</div>
	<div class="fitem">
		<label>类型：</label>
		<input name="typeName" style="width: 170px;" class="mini-combobox" valueField="keyName" required="true" textField="keyValue"
	        url="dictionary_key_type_view.do" popupWidth="150px;" popupHeight="130px;">
	</div>
</form>
<div style="text-align:center;padding:5px;">
    <a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>       
    <a class="mini-button" onclick="window.CloseOwnerWindow();" style="width:60px;">取消</a>       
</div>
<script type="text/javascript">
mini.parse();
var form = new mini.Form("form1");
//标准方法接口定义
function SetData(data,row) {
	data = mini.clone(data);
	form.setData(row);
	form.setChanged(false);
	mini.getbyName("keyNameHidden").setValue(row.keyName);
}

function onOk() {
    SaveData();
}

function SaveData() {
    var o = form.getData(); 
    form.validate();
    if (form.isValid() == false || judgekeyName() == false) return;
    $.ajax({
        url: "dictionary_save_edit.do",
		type: 'post',
		dataType: 'json',
        data: o,
        cache: false,
        success: function (text) {
            if(text.success){
            	window.CloseOwnerWindow("succ");
            }else{
            	mini.alert("保存失败！");
            }
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert(jqXHR.responseText);
            window.CloseOwnerWindow();
        }
    });
}

//判断编号是否重复
function judgekeyName(){
	var keyName = mini.getbyName('keyName').getValue();
	var keyNameHidden = mini.getbyName('keyNameHidden').getValue();
	var flag = true;
	if(keyName.length > 0 && keyName != keyNameHidden){
  	    $.ajax({
  	    	url: "dictionary_ver_key.do?keyName=" + keyName,
  	    	dataType: 'json',
  	        cache: false,
	    	async: false,
 	        success: function (text) {
 	            if(text.result){
 	            	flag = true;
 	            }else{
 	            	mini.alert("字典表键重复请修改");
 	            	flag = false;
 	            }
 	        }
  	    });
	}
    return flag;
}
</script>
</body>
</html>